class Solution {
public:
    vector<bool> visted;
    int n;

    void dfs(vector<vector<int>>& rooms, int x)
    {
        visted[x] = true;
        n--;
        for (int i = 0; i < rooms[x].size(); i++)
        {
            if (visted[rooms[x][i]] == false) dfs(rooms, rooms[x][i]);
        }


    }
    bool canVisitAllRooms(vector<vector<int>>& rooms)
    {
        n = rooms.size();
        visted = vector<bool>(n, false);

        dfs(rooms, 0);

        return n == 0;
    }
};